﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperWebSocket.SubProtocol;
using System.Collections;
using Newtonsoft.Json;

namespace WebCommand.Command
{
    public class POKER : SubCommandBase<MySession>
    {
        public override void ExecuteCommand(MySession session, SubRequestInfo requestInfo)
        {
            var list = new List<PokerCard>();
            //list.Add(new PokerCard() { Card = 4 });
            Random r = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < 14; i++)
            {
                PokerCard card = new PokerCard() { Card = r.Next(14) };
                while (list.Contains(card))
                    card = new PokerCard() { Card = r.Next(14) };

                list.Add(card);
            }

            session.SendResponseAsync(string.Format("POKER {0}", JsonConvert.SerializeObject(new { List = list })));
        }

        public class PokerCard
        {
            public int Card { get; set; }

            public override bool Equals(object obj)
            {
                if (!(obj is PokerCard))
                    return false;

                PokerCard card = (PokerCard)obj;
                return card.Card == this.Card;
            }

            public override string ToString()
            {
                return Card.ToString();
            }
        }
    }
}
